import request from '@/utils/request';
import { customeAppId } from '@/config';

export async function orderListServer(data) {
  return request({
    url: '/product/v1/myOrder/selectPage',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
    data: data,
    method: 'POST',
  });
}

export async function confirmGetItemServer(data) {
  return request({
    url: '/product/order/confirmGetItem',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
    data: data,
    method: 'POST',
  });
}

export async function orderCancleServer(data) {
  return request({
    url: '/product/myOrder/cancel',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
    data: data,
    method: 'POST',
  });
}

export async function orderDetailServer(orderId) {
  return request({
    url: `/product/myOrder/orderDetail/${orderId}`,
    method: 'GET',
  });
}

export async function getOrderCancelReasonServer() {
  return request({
    url: '/product/myOrder/getOrderCancelReason',
    method: 'GET',
  });
}

export async function getOrderStatusServer(orderId) {
  return request({
    url: `/product/myOrder/getOrderStatus/${orderId}`,
    method: 'GET',
  });
}

//查询物流信息
export async function expressQueryServer(data) {
  return request({
    url: '/product/order/expressQuery',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
    data: data,
    method: 'POST',
  });
}

// 外卖创建订单
export async function createTakeawayOrderServer(data, noToast) {
  return request({
    url: '/product/v1/takeaway/createOrder',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
    data: data,
    method: 'POST',
    noToast,
  });
}

//发起售后
export async function applyAfterServiceServer(data) {
  let params = '';
  for (let key in data) {
    params += `${key}=${data[key]}&`;
  }
  params = params.substr(0, params.length - 1);
  return request({
    url: `/product/orderAdjustment/applyAfterService?${params}`,
    method: 'GET',
    noToast: true,
  });
}

//申请售后
export async function applyRefundServer(data) {
  return request({
    url: '/product/orderAdjustment/applyRefund',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
    data: data,
    method: 'POST',
    noToast: true,
  });
}

//撤销售后
export async function cancelRefundServer(id) {
  return request({
    url: `/product/orderAdjustment/cancelRefund/${id}`,
    method: 'GET',
  });
}

//售后换货时确认收货
export async function confirmGetItemApplyServer(id) {
  return request({
    url: `/product/orderAdjustment/confirmGetItem/${id}`,
    method: 'GET',
  });
}

//售后列表
export async function adjustmentListServer(data) {
  return request({
    url: '/product/v1/orderAdjustment/selectMyPageList',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
    data: data,
    method: 'POST',
  });
}

//售后详情
export async function getAdjustmentDetailServer(id) {
  return request({
    url: `/product/orderAdjustment/getMyAdjustmentDetail/${id}`,
    method: 'GET',
  });
}

export async function selectActivityAmountServer({ orderId, payType, bizScene }) {
  return request({
    url: `/marketing/app/paymentDiscountActivity/selectActivityAmount?orderId=${orderId}&payway=${payType}&bizScene=${bizScene}`,
    method: 'GET',
  });
}

// 收银台获取支付优惠活动
export async function affirmActivityServer(data) {
  return request({
    url: `/game/app/activity/activityMessage/${customeAppId}`,
    method: 'GET',
    data,
  });
}
